package com.trkj.controller.cf;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trkj.pojo.Duty;
import com.trkj.pojo.Organization;
import com.trkj.pojo.OrganizationArea;
import com.trkj.pojo.OrganizationStructure;
import com.trkj.pojo.Position;
import com.trkj.pojo.StaffInformation;
import com.trkj.service.cf.DefinepositionSrevice;
import com.trkj.service.cf.DefinetissueService;
import com.trkj.service.cf.OrganizationAreaService;
import com.trkj.service.cf.OrganizationStructureService;
import com.trkj.service.wdm.DutyService;

@Controller
public class OperationController {
	@Autowired
	private OrganizationStructureService organizationStructureService;
	@Autowired
	private OrganizationAreaService organizationAreaService;
	@Autowired
	private DefinetissueService definetissueSrevice;
	@Autowired
	private HttpSession session;
	@Autowired
	private DefinepositionSrevice definepositionSrevice;
	@Autowired
	private DutyService dutyService;

	// 组织结构版本 搜索
	@GetMapping("byname")
	@ResponseBody
	public List<OrganizationStructure> login1() {
		return organizationStructureService.OrganizationStructureall();
	}

	@GetMapping("organizationpages")
	@ResponseBody
	public Map userPage(Integer page, Integer rows) {
		long total = organizationStructureService.pageCount();
		List<OrganizationStructure> list = organizationStructureService.userPage(page, rows);
		Map map = new HashMap<>();
		map.put("total", total);
		map.put("rows", list);
		return map;
	}

	// 搜索
	@GetMapping("organizationalversion_searchbox")
	@ResponseBody
	public List<OrganizationStructure> alversionquery(String versionName) {
		List<OrganizationStructure> list = organizationStructureService.filedByName(versionName);
		return list;
	}

	// 删除
	@GetMapping("organizationalversion_remove")
	@ResponseBody
	public void organizationremove(Long organsId) {
		organizationStructureService.organizationremove(organsId);
	}

	@GetMapping("enroll")
	@ResponseBody
	public void userEnroll(Long organsId, String versionName, Timestamp organsStartdate, Timestamp organsEnddate,
			String organsRemark, Integer organsState) {

		organizationStructureService.OrganizationStructureadds(organsId, versionName, organsStartdate, organsEnddate,
				organsRemark, organsState);
	}

	// b版本编辑
	@GetMapping("organizationupdate")
	@ResponseBody
	public void organizationEnroll(Long organsId, String versionName, String organsRemark, Integer organsState) {
		System.out.println(organsId + "" + versionName);
		organizationStructureService.organizationupdate(organsId, versionName, organsRemark, organsState);
	}

	/**
	 * 
	 * 组织区域 orgareaName
	 */
	@GetMapping("areapages")
	@ResponseBody
	public Map OrganizationPage(Integer page, Integer rows) {
		long total = organizationAreaService.pageCount();
		List<OrganizationArea> list = organizationAreaService.orgareaPage(page, rows);
		Map map = new HashMap<>();
		map.put("total", total);
		map.put("rows", list);
		return map;
	}

	// 组织区域搜索 名字
	@GetMapping("organizationArea_searchbox")
	@ResponseBody
	public List<OrganizationArea> Areaquery(String orgareaName) {
		List<OrganizationArea> list = organizationAreaService.filedByName(orgareaName);
		return list;
	}

	// 新增
	@GetMapping("organizationadd")
	@ResponseBody
	public void regionalEnroll(Long orgareaId1, String orgareaName, String orgareaRemark) {
		System.out.println(orgareaId1 + "" + orgareaName);
		organizationAreaService.regionalupdate(orgareaId1, orgareaName == null ? "中国" : orgareaName,
				orgareaRemark == null ? "暂无详情" : orgareaRemark);
	}

	// 删除
	@PostMapping("organizationArea_remove")
	@ResponseBody
	public void organizationArearemove(Long orgareaId1) {
		organizationAreaService.organizationArearemove(orgareaId1);
	}

	// 编辑
	@GetMapping("organizationArea_update")
	@ResponseBody
	public void organizationAreaeEdit(Long orgareaId1, String orgareaName, String orgareaRemark) {

		organizationAreaService.organizationAreaupdate(orgareaId1, orgareaName, orgareaRemark);
	}

	/**
	 * 
	 * 定义组织
	 */

	@GetMapping("definetissuepages")
	@ResponseBody
	public Map definetissuePage(Integer page, Integer rows) {
		long total = definetissueSrevice.pageCount();
		List<Organization> list = definetissueSrevice.Page(page, rows);
		Map map = new HashMap<>();
		map.put("total", total);
		map.put("rows", list);
		return map;
	}

	// 搜索
	@GetMapping("definetissue_searchbox")
	@ResponseBody
	public List<Organization> definetissuequery(String organiName) {
		List<Organization> list = definetissueSrevice.filedByName(organiName);
		return list;
	}

	// 新增
	@GetMapping("definetissueadd")
	@ResponseBody
	public void organizationEnroll(String organiName, String organiRemarks, HttpSession mo) {
		System.out.println(organiName);
		StaffInformation ss = (StaffInformation) mo.getAttribute("staff");
		definetissueSrevice.definetissueupdate(organiName, organiRemarks, ss.getStainName());
	}

	// 删除
	@PostMapping("definetissue_remove")
	@ResponseBody
	public void definetissueremove(Long organiId) {
		definetissueSrevice.definetissueremove(organiId);
	}

	// 编辑
	@GetMapping("definetissue_update")
	@ResponseBody
	public void definetissueEdit(Long organiId, String organiName, String organiRemarks) {
		System.out.println(organiId);
		definetissueSrevice.definetissueupdate(organiId, organiName, organiRemarks);
	}

	/**
	 * 
	 * 定义职位
	 */

	@GetMapping("defineposition_pages")
	@ResponseBody
	public Map definepositionPage(Integer page, Integer rows) {
		long total = definepositionSrevice.pageCount();
		List<Position> list = definepositionSrevice.Page(page, rows);
		Map map = new HashMap<>();
		map.put("total", total);
		map.put("rows", list);
		return map;
	}

	// 新增
	@GetMapping("defineposition_add")
	@ResponseBody
	public void definepositionEnroll(String positionName, String positionRemark) {
		System.out.println(positionName);
		definepositionSrevice.definepositionadd(positionName, positionRemark);
	}

	// 编辑
	@GetMapping("defineposition_update")
	@ResponseBody
	public void definepositionEdit(Long positionId, String positionName, String positionRemark) {
		System.out.println(positionId);
		definepositionSrevice.definepositionupdate(positionId, positionName, positionRemark);
	}

	// 删除
	@PostMapping("defineposition_remove")
	@ResponseBody
	public void definepositionremove(Long positionId) {
		definepositionSrevice.definepositionremove(positionId);
	}

	// 搜索
	@GetMapping("defineposition_searchbox")
	@ResponseBody
	public List<Position> definepositionquery(String positionName) {
		List<Position> list = definepositionSrevice.filedByName(positionName);
		return list;
	}

	/**
	 * 定义职务
	 */
	@GetMapping("defineduty_pages")
	@ResponseBody
	public Map definedutyPage(Integer page, Integer rows) {
		long total = dutyService.queryByCount();
		List<Duty> list = dutyService.queryByPage(page, rows);
		Map map = new HashMap<>();
		map.put("total", total);
		map.put("rows", list);
		return map;
	}

	// 新增
/*	@GetMapping("defineduty_add")
	@ResponseBody
	public void definedutyEnroll(Long dutyId, String dutyName) {
		System.out.println(dutyId);
		dutyService.definedutyadd(dutyId, dutyName);
	}*/

	// 删除
	@PostMapping("defineduty_remove")
	@ResponseBody
	public void definedutyremove(Long dutyId) {
		dutyService.definedutyremove(dutyId);
	}

	// 搜索
/*	@GetMapping("defineduty_searchbox")
	@ResponseBody
	public List<Duty> definedutyquery(String dutyName) {
		List<Duty> list = dutyService.filedByName(dutyName);
		return list;
	}*/
	/**
	 * 定义工作职责
	 */
}
